$(function(){

   /*手术操作JS开始*/
    /*新增按钮事件*/
   
   
   /*选项卡切换*/
    $.each($("#navli li"),function(i,item) {
        $(item).on("click", function (){
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#operation"+$(this).attr("data-index")).show().siblings().hide();
        });
      });
    /*手术操作JS结束*/

    /*重症监护*/
    $.each($("#icu_ul li"),function(i,item) {
        $(item).on("click", function (){
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#icu_records_div"+$(this).attr("data-index")).show().siblings().hide();
        });
    });
    
    if($("#icu_ul li").length>0){
    	$("#icu_ul li").first().click();
    }else{
    	add_intensiveCareRecord();
    }
    
    /*产科记录*/
    $.each($("#obstetricalRecord_li li"),function(i,item) {
        $(item).on("click", function (){
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#obestetricalRecord"+$(this).attr("data-index")).show().siblings().hide();
        });
    });
    if($("#nurseRecordsTable tbody tr").length == 0){
    	add_nurseRecord();
    }
    
    if($("#drugAllergyRecordsTable tbody tr").length == 0){
    	add_drugAllergyRecord();
    }
    $("select[name='radiologAndPathologDiagCode']").change(function(){
		var obj = $(this);
		var value = obj.val();
		var text = obj.find("option:selected").text();
		if(value == ""){
			text = "";
		}
		$("#"+obj.attr("id")+"NameHidden").val(text)
		
	});
    
    $("select[data-select='drugAllergyType']").change(function(){
		var obj = $(this);
		var value = obj.val();
		var text = obj.find("option:selected").text();
		if(value == ""){
			text = "";
		}
		obj.siblings("input[data-select='"+obj.attr("data-select")+"NameHidden']").val(text);
		
		//$("#"+obj.attr("data-select")+"NameHidden").val(text)
	});
    
    
    $("select[data-select='pressureSoreCradle']").change(function(){
		var obj = $(this);
		var value = obj.val();
		var text = obj.find("option:selected").text();
		if(value == ""){
			text = "";
		}
		obj.siblings("input[data-select='"+obj.attr("data-select")+"NameHidden']").val(text);
		
		//$("#"+obj.attr("data-select")+"NameHidden").val(text)
	});
    
    $("select[data-multiple='data-multiple']").multiselect();
    
    $("select[data-select-multi='pressureSorePart']").change(function(){
    	var obj = $(this);
		var value = obj.val();
		var options = obj.find("option:selected");
		var text ="";
		for(var i=0;i<options.length;i++){
			if(text.length >0){
				text =  text + ","+$(options[i]).text();
			}else{
				text = $(options[i]).text();
			}
		}
		obj.siblings("input[data-select-multi='"+obj.attr("data-select")+"NamesHidden']").val(text);
    });
    
    if($("#pressureSoreRecordsTable tbody tr").length == 0){
    	add_pressureSoreRecord();
    }
});
/*疾病诊断 JS 开始*/
/*次要诊断 新增按钮事件*/
function add_diseaseDiagnos(){
	 var diseaseDiagnosCountOjb = $("#diseaseDiagnosCount");
	 var count = parseInt(diseaseDiagnosCountOjb.val());
     var htmlTr=$("#diseaseDiagnosList tr:eq(2)").clone();
     
     var diagnoseTypeIdOjb= htmlTr.find("select[name='hospitalizationDiagnosis[0].diagnoseTypeId']");
     diagnoseTypeIdOjb.attr("name","hospitalizationDiagnosis["+count+"].diagnoseTypeId");
     diagnoseTypeIdOjb.val("");
     var diagnoseTypeNameOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].diagnoseTypeName']");
     diagnoseTypeNameOjb.attr("name","hospitalizationDiagnosis["+count+"].diagnoseTypeName");
     diagnoseTypeNameOjb.val("");
     
     
     var diseaseFormControlObj= htmlTr.find("#diseaseFormControl-0");
     diseaseFormControlObj.attr("id","diseaseFormControl-"+count);
     diseaseFormControlObj.val("");
     var searchSuggestObj= htmlTr.find("#search_suggest0");
     searchSuggestObj.attr("id","search_suggest"+count);
     
     var diseaseCodeOjb= htmlTr.find("#getjbzdbm-0");
     diseaseCodeOjb.attr("id","getjbzdbm-"+count);
     diseaseCodeOjb.attr("name","hospitalizationDiagnosis["+count+"].diseaseCode");
     diseaseCodeOjb.val("");
     
     var diseaseNameOjb= htmlTr.find("#getjbmc-0");
     diseaseNameOjb.attr("id","getjbmc-"+count);
     diseaseNameOjb.attr("name","hospitalizationDiagnosis["+count+"].diseaseName");
     diseaseNameOjb.val("");
     
     var inHospitalDiseaseStateIdOjb= htmlTr.find("select[name='hospitalizationDiagnosis[0].inHospitalDiseaseStateId']");
     inHospitalDiseaseStateIdOjb.attr("name","hospitalizationDiagnosis["+count+"].inHospitalDiseaseStateId");
     inHospitalDiseaseStateIdOjb.val("");
     
     var inHospitalDiseaseStateNameOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].inHospitalDiseaseStateName']");
     inHospitalDiseaseStateNameOjb.attr("name","hospitalizationDiagnosis["+count+"].inHospitalDiseaseStateName");
     inHospitalDiseaseStateNameOjb.val("");
     
     var treatmentOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].treatment']");
     treatmentOjb.attr("name","hospitalizationDiagnosis["+count+"].treatment");
     var istreatmentOjb= htmlTr.find("#isTreatment-0");
     istreatmentOjb.attr("id","isTreatment-"+count);
     istreatmentOjb.removeAttr("checked");
     
     var treatmentResultIdOjb= htmlTr.find("select[name='hospitalizationDiagnosis[0].treatmentResultId']");
     treatmentResultIdOjb.attr("name","hospitalizationDiagnosis["+count+"].treatmentResultId");
     treatmentResultIdOjb.val("");
     
     var treatmentResultNameOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].treatmentResultName']");
     treatmentResultNameOjb.attr("name","hospitalizationDiagnosis["+count+"].treatmentResultName");
     treatmentResultNameOjb.val("");
     
     var confirmedDateOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].confirmedDate']");
     confirmedDateOjb.attr("name","hospitalizationDiagnosis["+count+"].confirmedDate");
     confirmedDateOjb.val("");
     
     var diagnoseSortOjb= htmlTr.find("input[name='hospitalizationDiagnosis[0].diagnoseSort']");
     diagnoseSortOjb.attr("name","hospitalizationDiagnosis["+count+"].diagnoseSort");
     diagnoseSortOjb.val("");
     
     var diagnoseSortOjb= htmlTr.find("#diagnosisDelete0");
     diagnoseSortOjb.attr("id","diagnosisDelete"+count);
     diagnoseSortOjb.removeAttr("hidden");
     diagnoseSortOjb.on("click",function(){
    	 del(this);
     });
     $("#diseaseDiagnosList tbody").append(htmlTr);
     diseaseDiagnosCountOjb.val(count +1);
     selectDiseaseControl();
     changeDiseaseDiagnos();
}

/*疾病诊断JS结束*/

/*手术操作新增按钮事件*/
function addOP(){
	var operationCountOjb = $("#operationCount");
	var count = parseInt(operationCountOjb.val());
    /*增加navli*/
    var addli=$("#navli li:eq(0)").clone();
    addli.text("记录"+(count+1));
    addli.attr("data-index",count);
    $("#navli").append(addli);
    addli.addClass("selected").siblings().removeClass("selected");
    /*增加内容*/
    var add_content=$("#operations>div:first").clone();
    var cloneDivIndex = add_content.attr("id").replace('operation','');
    /*克隆后的元素将内容置空*/
    add_content.attr("id","operation"+count);
    
    add_content.find("input:not([type='radio'])").val("");
    $.each(add_content.find("input[name^='operations["+cloneDivIndex+"].']"), function(i,item) {    
    	var inputName = $(item).attr("name");
    	var changeName = inputName.replace("["+cloneDivIndex+"]","["+count+"]");
        $(item).attr("name",changeName);
         if($(item).attr("type")=="radio"){
        	$(item).filter("input[value='false']").prop("checked",true);
        }
    });
    
    add_content.find("#doctorFormControl-operations"+cloneDivIndex+"surgeryOfDoctor").attr("id","doctorFormControl-operations"+count+"surgeryOfDoctor")
    add_content.find("#operations"+cloneDivIndex+"surgeryOfDoctorDiv").attr("id","operations"+count+"surgeryOfDoctorDiv")
    add_content.find("#operations"+cloneDivIndex+"surgeryOfDoctorId").attr("id","operations"+count+"surgeryOfDoctorId")
    
    add_content.find("#doctorFormControl-operations"+cloneDivIndex+"anaesthesiaOfDoctor").attr("id","doctorFormControl-operations"+count+"anaesthesiaOfDoctor")
    add_content.find("#operations"+cloneDivIndex+"anaesthesiaOfDoctorDiv").attr("id","operations"+count+"anaesthesiaOfDoctorDiv")
    add_content.find("#operations"+cloneDivIndex+"anaesthesiaOfDoctorId").attr("id","operations"+count+"anaesthesiaOfDoctorId")
    
   
    add_content.find("#doctorFormControl-operations"+cloneDivIndex+"firstOpsAssistant").attr("id","doctorFormControl-operations"+count+"firstOpsAssistant")
    add_content.find("#operations"+cloneDivIndex+"firstOpsAssistantDiv").attr("id","operations"+count+"firstOpsAssistantDiv")
    add_content.find("#operations"+cloneDivIndex+"firstOpsAssistantId").attr("id","operations"+count+"firstOpsAssistantId")
    
   
    
    add_content.find("#doctorFormControl-operations"+cloneDivIndex+"secondOpsAssistant").attr("id","doctorFormControl-operations"+count+"secondOpsAssistant")
    add_content.find("#operations"+cloneDivIndex+"secondOpsAssistantDiv").attr("id","operations"+count+"secondOpsAssistantDiv")
    add_content.find("#operations"+cloneDivIndex+"secondOpsAssistantId").attr("id","operations"+count+"secondOpsAssistantId")
    
   
    
    $.each(add_content.find("input[id^=operationCodeShow]"), function(i) {    
    	add_content.find("#operationCodeShow-"+cloneDivIndex+i).attr("id","operationCodeShow-"+count+i);
        add_content.find("#operationCodeDiv"+cloneDivIndex+i).attr("id","operationCodeDiv"+count+i);
        add_content.find("#operationCode"+cloneDivIndex+i).attr("id","operationCode"+count+i);
        add_content.find("#operationName"+cloneDivIndex+i).attr("id","operationName"+count+i);
    });

    add_content.find("textarea").val("");
    $.each(add_content.find("textarea[name^='operations["+cloneDivIndex+"].']"), function(i,item) {    
    	var textareaName = $(item).attr("name");
    	var changeName = textareaName.replace("["+cloneDivIndex+"]","["+count+"]");
        $(item).attr("name",changeName);
    });

    $.each(add_content.find("select[name^='operations["+cloneDivIndex+"].']"), function(i,item) {    
    	var selectName = $(item).attr("name");
    	var changeName = selectName.replace("["+cloneDivIndex+"]","["+count+"]");
        $(item).attr("name",changeName);
        $(item).val("");
    });
    
    /*复制的元素添加*/
    $("#operations").append(add_content);
    add_content.show().siblings().hide();
    operationCountOjb.val(count+1);
    selectOperationControl();
    changeOperation();
    /*选项卡切换*/
    $.each($("#navli li"),function(i,item) {
        $(item).on("click", function (){
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#operation"+$(this).attr("data-index")).show().siblings().hide();
        });
    });
    selectDoctorControl();
}

/*手术删除操作*/
function delOP(){
    /*选项卡删除最后一项*/
	if($("#operations>div").length ==1){
		alert("请至少保留一项！！！");
		return;
	}
	var delete_option = $("#navli li[class='selected']");
	var delete_index = delete_option.attr("data-index");
	delete_option.remove();
	
    $("#navli li:last").addClass("selected").siblings().removeClass("selected");
    /*内容删除最后一项*/
    $("#operation"+delete_index).remove();
    $("#operations>div:last").show().siblings().hide();
}

/*输血记录新增*/
function addBlood(){
	var bloodTransfuseCountOjb = $("#bloodTransfuseCount");
	 var count = parseInt(bloodTransfuseCountOjb.val());
	var newBloodTr = $("#bloodTransfuseList tr:eq(2)").clone();
	var bloodTypeIdOjb= newBloodTr.find("select[name='bloodTransfusions[0].bloodTypeId']");
	bloodTypeIdOjb.attr("name","bloodTransfusions["+count+"].bloodTypeId");
	bloodTypeIdOjb.val("");
	
	var bloodTypeNameOjb= newBloodTr.find("input[name='bloodTransfusions[0].bloodTypeName']");
	bloodTypeNameOjb.attr("name","bloodTransfusions["+count+"].bloodTypeName");
	bloodTypeNameOjb.val("");
	
	 var bloodTransfusionDateOjb= newBloodTr.find("input[name='bloodTransfusions[0].bloodTransfusionDate']");
	 bloodTransfusionDateOjb.attr("name","bloodTransfusions["+count+"].bloodTransfusionDate");
	 bloodTransfusionDateOjb.val("");
	 
	 var bloodTransfusionResponseOjb= newBloodTr.find("input[name='bloodTransfusions[0].bloodTransfusionResponse']");
	 bloodTransfusionResponseOjb.attr("name","bloodTransfusions["+count+"].bloodTransfusionResponse");
	 bloodTransfusionResponseOjb.filter("input[value='false']").prop("checked",true);
   
	 var redBloodCellVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].redBloodCellVolume']");
	 redBloodCellVolumeOjb.attr("name","bloodTransfusions["+count+"].redBloodCellVolume");
	 redBloodCellVolumeOjb.val("");
	 
	 
	 var thrombocyteVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].thrombocyteVolume']");
	 thrombocyteVolumeOjb.attr("name","bloodTransfusions["+count+"].thrombocyteVolume");
	 thrombocyteVolumeOjb.val("");
	 
	 var plasmaVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].plasmaVolume']");
	 plasmaVolumeOjb.attr("name","bloodTransfusions["+count+"].plasmaVolume");
	 plasmaVolumeOjb.val("");
	 
	 var wholeBloodVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].wholeBloodVolume']");
	 wholeBloodVolumeOjb.attr("name","bloodTransfusions["+count+"].wholeBloodVolume");
	 wholeBloodVolumeOjb.val("");
	 
	 var autoBloodVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].autoBloodVolume']");
	 autoBloodVolumeOjb.attr("name","bloodTransfusions["+count+"].autoBloodVolume");
	 autoBloodVolumeOjb.val("");
	 var albuminVolumeOjb= newBloodTr.find("input[name='bloodTransfusions[0].albuminVolume']");
	 albuminVolumeOjb.attr("name","bloodTransfusions["+count+"].albuminVolume");
	 albuminVolumeOjb.val("");
	 
	 var otherInfoOjb= newBloodTr.find("input[name='bloodTransfusions[0].otherInfo']");
	 otherInfoOjb.attr("name","bloodTransfusions["+count+"].otherInfo");
	 otherInfoOjb.val("");
	 
	 var deleteBloodTransfusionsOjb= newBloodTr.find("#deleteBloodTransfusions0");
	 deleteBloodTransfusionsOjb.attr("id","deleteBloodTransfusions"+count);
	 deleteBloodTransfusionsOjb.removeAttr("hidden");
	 deleteBloodTransfusionsOjb.on("click",function(){
		 del(this);
	    });
    $("#bloodTransfuseList tbody").append(newBloodTr);
    bloodTransfuseCountOjb.val(count +1);
    changeBloodTypeRecord();
}

/*输血记录结束*/


/*删除*/
function del(target){
    $(target).closest("tr").remove();
}

/*转科记录*/
function addTransferNote(){
    var add_transferNote=$("#transferNote tbody>tr:eq(2)").clone();
    var changeOfficeCountObj = $("#changeOfficeCount");
    var count = parseInt(changeOfficeCountObj.val());
	var inOfficeIdObj= add_transferNote.find("select[name='hospitalizationChangeOffices[0].inOfficeId']");
	inOfficeIdObj.attr("name","hospitalizationChangeOffices["+count+"].inOfficeId");
	inOfficeIdObj.val("");
	
	var inOfficeNameObj= add_transferNote.find("input[name='hospitalizationChangeOffices[0].inOfficeName']");
	inOfficeNameObj.attr("name","hospitalizationChangeOffices["+count+"].inOfficeName");
	inOfficeNameObj.val("");
	
	var outOfficeIdObj= add_transferNote.find("select[name='hospitalizationChangeOffices[0].outOfficeId']");
	outOfficeIdObj.attr("name","hospitalizationChangeOffices["+count+"].outOfficeId");
	outOfficeIdObj.val("");
	
	var outOfficeNameObj= add_transferNote.find("input[name='hospitalizationChangeOffices[0].outOfficeName']");
	outOfficeNameObj.attr("name","hospitalizationChangeOffices["+count+"].outOfficeName");
	outOfficeNameObj.val("");
	
	var changeOfficeDateObj= add_transferNote.find("input[name='hospitalizationChangeOffices[0].changeOfficeDate']");
	changeOfficeDateObj.attr("name","hospitalizationChangeOffices["+count+"].changeOfficeDate");
	changeOfficeDateObj.val("");
    
	var changeOfficeRemarksObj= add_transferNote.find("input[name='hospitalizationChangeOffices[0].changeOfficeRemarks']");
	changeOfficeRemarksObj.attr("name","hospitalizationChangeOffices["+count+"].changeOfficeRemarks");
	changeOfficeRemarksObj.val("");
    
	 var deleteChangeOfficeObj= add_transferNote.find("#deleteChangeOffice0");
	 deleteChangeOfficeObj.attr("id","deleteChangeOffice"+count);
	 deleteChangeOfficeObj.removeAttr("hidden");
	 deleteChangeOfficeObj.on("click",function(){
		 del(this);
	    });
	 $("#transferNote tbody").append(add_transferNote);
    changeOfficeCountObj.val(count +1);
    changeMedicalOffice();
}
/**转科记录结束*/


/*产科记录*/
function addObstetricalRecord(){
	 var obstetricalRecordCountObj = $("#obstetricalRecordCount");
	 var obstetricalRecordCount = parseInt(obstetricalRecordCountObj.val());
    /*增加navli*/
    var addli=$("#obstetricalRecord_li li:eq(0)").clone();
    addli.text("记录"+(obstetricalRecordCount+1));
    addli.attr("data-index",obstetricalRecordCount);
    $("#obstetricalRecord_li").append(addli);
    addli.addClass("selected").siblings().removeClass("selected");
    /*增加内容*/
    var add_content=$("#obstetricalRecord_content>div:eq(0)").clone();
    add_content.attr("id","obestetricalRecord"+obstetricalRecordCount);
    /*克隆后的元素将内容置空*/
    add_content.find("input:not([type='radio'])").val("");
    $.each(add_content.find("input[name^='obstetricalRecords[0]']"),function(i,item) {
    	var inputName = $(item).attr("name");
    	inputName = inputName.replace("[0]","["+obstetricalRecordCount+"]");
        $(item).attr("name",inputName);
        if($(item).attr("type")=="radio"){
        	$(item).filter("input[value='false']").prop("checked",true);
        }
    });
    
    add_content.find("select").val("");
    $.each(add_content.find("select[name^='obstetricalRecords[0]']"),function(i,item) {
    	var selectName =$(item).attr("name");
    	selectName = selectName.replace("[0]","["+obstetricalRecordCount+"]");
        $(item).attr("name",selectName);
    });
    
    $.each(add_content.find("input[id^='neonateDiseaseFormControl-']"), function(i) { 
    	add_content.find("#neonateDiseaseFormControl-0"+(i+1)).attr("id","neonateDiseaseFormControl-"+obstetricalRecordCount+(i+1));
    	add_content.find("#search_suggest0"+(i+1)).attr("id","search_suggest"+obstetricalRecordCount+(i+1));
        add_content.find("#neonateDiseaseCode0"+(i+1)).attr("id","neonateDiseaseCode"+obstetricalRecordCount+(i+1));
        add_content.find("#neonateDiseaseName0"+(i+1)).attr("id","neonateDiseaseName"+obstetricalRecordCount+(i+1));
    });
    
    /*复制的元素添加*/
    $("#obstetricalRecord_content").append(add_content);
    add_content.show().siblings().hide();
    /*选项卡切换*/
    $.each($("#obstetricalRecord_li li"),function(i,item) {
        $(item).on("click", function (){
            $(this).addClass("selected").siblings().removeClass("selected");
            $("#obestetricalRecord"+$(this).attr("data-index")).show().siblings().hide();
        });
    });
    obstetricalRecordCountObj.val(obstetricalRecordCount+1);
    selectNeonateDiseaseControl();
    changeObstetricalRecord();
}

function delObstetricalRecord(){
	if($("#obstetricalRecord_content>div").length ==1){
		alert("请至少保留一项！！！");
		return;
	}
	/*选项卡删除选中的一项*/
	var delete_obstetricalRecord = $("#obstetricalRecord_li li[class='selected']");
	var delete_index = delete_obstetricalRecord.attr("data-index");
	delete_obstetricalRecord.remove();
	$("#obestetricalRecord"+delete_index).remove();
	//删除后选中最后一项
    $("#obstetricalRecord_li li:last").addClass("selected").siblings().removeClass("selected");
    $("#obstetricalRecord_content>div:last").show().siblings().hide();
    $("#obstetricalRecordCount").val(parseInt($("#obstetricalRecordCount").val())-1);
}
/**产科记录结束*/


/**医院感染*/
function add_hospitalInfection(){
	 var hospitalInfectionCountObj = $("#hospitalInfectionCount");
	 var hospitalInfectionCount = parseInt(hospitalInfectionCountObj.val());
 
   /*增加内容*/
   var add_content=$("#hospitalInfectionTable tr:eq(2)").clone();
   $.each(add_content.find("input[name^='hospitalInfects[0]']"),function(i,item) {
   	var inputName = $(item).attr("name");
   	inputName = inputName.replace("[0]","["+hospitalInfectionCount+"]");
       $(item).attr("name",inputName);
       $(item).val("");
   });
   
   add_content.find("select").val("");
   $.each(add_content.find("select[name^='hospitalInfects[0]']"),function(i,item) {
   	var selectName =$(item).attr("name");
   	selectName = selectName.replace("[0]","["+hospitalInfectionCount+"]");
       $(item).attr("name",selectName);
   });

   var deleteHospitalInfectObj = add_content.find("#deleteHospitalInfection0");
   deleteHospitalInfectObj.attr("id","deleteHospitalInfection"+hospitalInfectionCount);
   deleteHospitalInfectObj.removeAttr("hidden");
   
   deleteHospitalInfectObj.on("click",function(){
	   del(this);
   });
   
   /*复制的元素添加*/
   $("#hospitalInfectionTable tbody").append(add_content);
 
   hospitalInfectionCountObj.val(hospitalInfectionCount+1);
   changeHospitalInfection();
}

function add_nurseRecord(){
 var nurseRecordCountObj = $("#nurseRecordCount");
 var nurseRecordCount = parseInt(nurseRecordCountObj.val());
 
   /*增加内容*/
   var add_content=$("#nurseRecordTemplateTr").clone();
   add_content.removeAttr("id");
   $.each(add_content.find("input[name^='nurseRecords[0]']"),function(i,item) {
   	var inputName = $(item).attr("name");
   	inputName = inputName.replace("[0]","["+nurseRecordCount+"]");
       $(item).attr("name",inputName);
       $(item).val("");
   });
   $("#nurseRecordsTable tbody").append(add_content);
   nurseRecordCountObj.val(nurseRecordCount + 1);
}

function delete_nurseRecord(obj){
	$(obj).parent().parent().remove();
}

function add_intensiveCareRecord(){
 var intensiveCareRecordCountObj = $("#intensiveCareRecordCount");
	var intensiveCareRecordCount = parseInt(intensiveCareRecordCountObj.val());

	var addli = $("#template_icu_ul li:eq(0)").clone();
	addli.text("记录" + (intensiveCareRecordCount + 1));
	addli.attr("data-index", intensiveCareRecordCount);

	$("#icu_ul").append(addli);
	addli.click(function() {
		$(this).addClass("selected").siblings().removeClass("selected");
        $("#icu_records_div"+$(this).attr("data-index")).show().siblings().hide();
	});
	addli.addClass("selected").siblings().removeClass("selected");
	/* 增加内容 */
	var add_content = $("#template_icu_records_div").clone();
	add_content.attr("id", "icu_records_div" + intensiveCareRecordCount);
	$.each(add_content.find("input[name^='intensiveCareRecords[0]']"),
			function(i, item) {
				var inputName = $(item).attr("name");
				
				inputName = inputName.replace("[0]", "["
						+ intensiveCareRecordCount + "]");
				$(item).attr("name", inputName);
				var inputType = $(item).attr("type");
				if(inputType !="radio"){
					$(item).val("");
				}
				
			});
	add_content.find("select").val("");
	$.each(add_content.find("select[name^='intensiveCareRecords[0]']"),
			function(i, item) {
				var selectName = $(item).attr("name");
				selectName = selectName.replace("[0]", "["
						+ intensiveCareRecordCount + "]");
				$(item).attr("name", selectName);
			});
	$.each(add_content.find("select[name$='iCUTypeId']"),
			function(i, item) {
				$(item).change(function(){
					var obj = $(this);
					var value = obj.val();
					var text = obj.find("option:selected").text();
					if(value == ""){
						text = "";
					}
					obj.siblings("input[name$='iCUTypeName']").val(text);
					/* $("#"+obj.attr("id")+"NameHidden").val(text) */
					
				});
			});
	$.each(add_content.find("textarea[name^='intensiveCareRecords[0]']"),
			function(i, item) {
				var selectName = $(item).attr("name");
				selectName = selectName.replace("[0]", "["
						+ intensiveCareRecordCount + "]");
				$(item).attr("name", selectName);
			});

	$("#icu_records_div").append(add_content);
	add_content.show().siblings().hide();
	intensiveCareRecordCountObj.val(intensiveCareRecordCount + 1);
}

function delete_intensiveCareRecord(){
	var current_li = $("#icu_ul li[class='selected']");
	var current_index = current_li.attr("data-index");
	var next_li = current_li.next();
	current_li.remove();
	$("#icu_records_div"+current_index).remove();
	if(next_li.length > 0){
		next_li.click();
	}else{
		$("#icu_ul li").last().click();
	}
}


function add_drugAllergyRecord(){
	var drugAllergyRecordCountObj = $("#drugAllergyRecordCount");
	var drugAllergyRecordCount = parseInt(drugAllergyRecordCountObj.val());
	 
	/*增加内容*/
	var add_content=$("#drugAllergyRecordTemplateTr").clone();
	add_content.removeAttr("id");
	$.each(add_content.find("input[name^='drugAllergyRecords[0]']"),function(i,item) {
		var inputName = $(item).attr("name");
		inputName = inputName.replace("[0]","["+drugAllergyRecordCount+"]");
		$(item).attr("name",inputName);
		$(item).val("");
		
	});
	
	$.each(add_content.find("select[name^='drugAllergyRecords[0]']"),function(i,item) {
		var inputName = $(item).attr("name");
		inputName = inputName.replace("[0]","["+drugAllergyRecordCount+"]");
		$(item).attr("name",inputName);
		$(item).val("");
		var dataSelect = $(item).attr("data-select");
		if(dataSelect == "drugAllergyType"){
			$(item).change(function(){
				var obj = $(this);
				var value = obj.val();
				var text = obj.find("option:selected").text();
				if(value == ""){
					text = "";
				}
				$(item).siblings("input[data-select='"+obj.attr("data-select")+"NameHidden']").val(text);
				
				//$("#"+obj.attr("data-select")+"NameHidden").val(text)
			});
		}
	});
	
	$("#drugAllergyRecordsTable tbody").append(add_content);
	drugAllergyRecordCountObj.val(drugAllergyRecordCount + 1);
}

function delete_drugAllergyRecord(obj){
	$(obj).parent().parent().remove();
}


function add_pressureSoreRecord(){
	var pressureSoreRecordCountObj = $("#pressureSoreRecordCount");
	var pressureSoreRecordCount = parseInt(pressureSoreRecordCountObj.val());
	 
	/*增加内容*/
	var add_content=$("#pressureSoreRecordTemplateTr").clone();
	add_content.removeAttr("id");
	$.each(add_content.find("input[name^='pressureSoreRecords[0]']"),function(i,item) {
		var inputName = $(item).attr("name");
		inputName = inputName.replace("[0]","["+pressureSoreRecordCount+"]");
		$(item).attr("name",inputName);
		$(item).val("");
		
	});
	
	$.each(add_content.find("select[name^='pressureSoreRecords[0]']"),function(i,item) {
		var inputName = $(item).attr("name");
		inputName = inputName.replace("[0]","["+pressureSoreRecordCount+"]");
		$(item).attr("name",inputName);
		$(item).val("");
		if($(item).attr("multiple") == 'multiple'){
			$(item).multiselect();
		}
		
		if($(item).attr("data-select")){
			$(item).change(function(){
				var obj = $(this);
				var value = obj.val();
				var text = obj.find("option:selected").text();
				if(value == ""){
					text = "";
				}
				obj.siblings("input[data-select='"+obj.attr("data-select")+"NameHidden']").val(text);
				
			});
		}else if($(item).attr("data-select-multi")){
			$(item).change(function(){
				
				var obj = $(this);
				var value = obj.val();
				var options = obj.find("option:selected");
				var text ="";
				for(var i=0;i<options.length;i++){
					if(text.length >0){
						text =  text + ","+$(options[i]).text();
					}else{
						text = $(options[i]).text();
					}
				}
				obj.parent().siblings("input[data-select-multi='"+obj.attr("data-select-multi")+"NamesHidden']").val(text);
			});
			
		}
		
	});
	
	$("#pressureSoreRecordsTable tbody").append(add_content);
	pressureSoreRecordCountObj.val(pressureSoreRecordCount + 1);
}

function delete_pressureSoreRecord(obj){
	$(obj).parent().parent().remove();
}
